package com.fer.service.impl;

import com.fer.mapper.BossManaMapper;
import com.fer.model.Boss;
import com.fer.service.BossService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BossServiceImpl implements BossService {

    @Autowired
    private BossManaMapper bossManaMapper;

    //登录
    @Override
    public Boss login(Boss boss) {
        return bossManaMapper.login(boss);
    }
    //注册
    @Override
    public void register(Boss boss) {
        bossManaMapper.register(boss);
    }

    @Override
    public String findUserByUsername(String username) {
        return bossManaMapper.findUserByUsername(username);
    }

    @Override
    public int updatePwd(Boss boss, String newPassword) {
        System.out.println("username:"+boss.getUsername());
        System.out.println("password:"+boss.getPassword());
        if (boss.getUsername() != null && !boss.getUsername().equals("") &&
        boss.getPassword() != null && !boss.getPassword().equals("")) {
            Boss user = bossManaMapper.login(boss);
            if (user != null) {
                System.out.println(boss.getUsername()+"&"+boss.getPassword());
                user.setPassword(newPassword);
                bossManaMapper.updatePwd(user);
                return 1; // 成功为1
            }
            else {
                return -1; // 原密码错误为-1
            }
        }
        return -2; // 其他情况，修改失败
    }

}
